package com.qxmly.fm;

import android.os.Bundle;

import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import com.qxmly.fm.adapters.IndicatorAdapter;
import com.qxmly.fm.adapters.MainContentAdapter;
import com.qxmly.fm.utils.LogUtil;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

public class MainActivity extends FragmentActivity {

    private static final String TAG ="MainActivity";
    private MagicIndicator mMagicIndicator;
    private ViewPager mViewPager;
    private IndicatorAdapter mIndicatorAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //透明状态栏
//        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//        getWindow().setStatusBarColor(Color.TRANSPARENT);
        initView();
        initEvent();
        //点播数据接口
        //接口说明：
        //此接口用于获取点播资源的内容分类，如：“有声小说”、“相声评书”等。
        //参数说明：
        //specificParams：对于本接口设置为null或者空Map对象
        //callback：回调接口，成功则返回CategoryList（字段描述见Model层.md）对象，失败则返回错误原因
//        Map<String, String> map = new HashMap<>();
//        CommonRequest.getCategories(map, new IDataCallBack<CategoryList>() {
//            @Override
//            public void onSuccess(@Nullable CategoryList categoryList) {
//                List<Category> categories = categoryList.getCategories();
//                if(categories != null){
//                    int size=categories.size();
//                    Log.d(TAG,"categories size-"+size);
//                    for(Category category : categories){
////                        Log.d(TAG,"category-"+ category.getCategoryName());
//                        LogUtil.d(TAG,"category-"+ category.getCategoryName());
//                    }
//                }
//
//            }
//
//            @Override
//            public void onError(int i, String s) {
////                Log.e(TAG,"error code -- " + i + "error msg ="+s);
//                LogUtil.e(TAG,"error code -- " + i + "error msg ="+s);
//
//            }
//        });

    }
    private void initEvent(){
        mIndicatorAdapter.setOnIndicatorTabClickListener(new IndicatorAdapter.OnIndicatorTabClickListener() {

            @Override
            public void onTabClick(int index) {
                LogUtil.d(TAG,"click index is ->"+index);
                if(mViewPager !=null){
                    mViewPager.setCurrentItem(index);
                }
            }
        });

        }



    private void initView() {
        mMagicIndicator = this.findViewById(R.id.magic_indicator1);
       // mMagicIndicator.setBackgroundColor(this.getResources().getColor(R.color.main_color));
        mIndicatorAdapter =new IndicatorAdapter(this);
        CommonNavigator commonNavigator =new CommonNavigator(this);
        commonNavigator.setAdjustMode(true);
        commonNavigator.setAdapter(mIndicatorAdapter);

        mViewPager = this.findViewById(R.id.view_pager);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        FragmentManager SupportFragmentManager = getSupportFragmentManager();
        MainContentAdapter mainContentAdapter  =new MainContentAdapter(SupportFragmentManager);
        mViewPager.setAdapter(mainContentAdapter);
        mMagicIndicator.setNavigator(commonNavigator);
        ViewPagerHelper.bind(mMagicIndicator, mViewPager);

    }
}